﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace WpfAlgorithm1
{
    class MathHelper
    {
        static public double Min(double a, double b)
        {
            if (a > b)
            {
                return b;
            }
            else
            {
                return a;
            }
        }
        static public double Max(double a, double b)
        {
            if (a < b)
            {
                return b;
            }
            else
            {
                return a;
            }
        }
        static public int Min(int X, int Y)
        {
            if (X > Y)
                return Y;
            return X;
        }
        static public bool IfnearlyEqual(double a, double b)
        {
            if (a - b < 1 || a - b > -1)
            {
                return true;
            }
            return false;
        }
        static public void MaxMinNorm(double[,] arr,int X,int Y)
        {
            double max = arr[0,0];
            double min = arr[0,0];
            foreach (double a in arr)
            {
                if (a > max)
                {
                    max = a;
                }
                else if (a < min)
                {
                    min = a;
                }
            }
            double temp = max - min;
            for (int i = 0; i < X; i++)
            {
                for (int j = 0; j < Y; j++)
                {
                    arr[i, j] = (arr[i, j] - min) / temp;
                }
            }
        }
        static public double Distance(Point X, Point Y)
        {
            double xd = X.X - Y.X;
            double yd = X.Y - Y.Y;
            double d = xd * xd + yd * yd;
            d = Math.Sqrt(d);
            return d;
        }
    }
}
